<template>
	<view class="loginpages">
		<view class="margin020">
			<!-- logo -->
			<view class="center_center row bak" style="">
				<image src="/static/logo.png" class="image" mode="scaleToFill"></image>
			</view>
			<!-- <view class="shouji">
				<image src="/static/login/dl_shouji.png" mode=""></image>
				<input type="number" placeholder="请输入手机号" v-model="tel" maxlength="11" />
			</view> -->
			<view class="shouji">
				<image src="/static/login/dl_shouji.png" mode=""></image>
				<input type="text" placeholder="请输入账号" v-model="username" maxlength="11" />
			</view>
			<view class="shouji">
				<image src="/static/login/dl_mima.png" mode=""></image>
				<input password type="text" placeholder="请输入密码" v-model="password" />
			</view>
			<view class="denglu" @click="denglu()">
				登录
			</view>
			<view class="denglu" style="background-color: rgb(109, 130, 175);" @click="register()">
				没有账号？立即注册
			</view>
		</view>
	</view>
</template>


<script>
export default {
	data() {
		return {
			username: '',  // 账号
			password: '',  // 密码
		};
	},
	methods: {
		// 登录方法
		async denglu() {
			if (!this.username) {
				uni.showToast({
					title: '请输入用户名',
					icon: 'none',
				});
				return;
			}
			if (!this.password) {
				uni.showToast({
					title: '请输入密码',
					icon: 'none',
				});
				return;
			}
			// 提交登录请求
			try {
				const res = await uni.request({
					url: 'http://123.56.82.144:8090/user/login',
					method: 'POST',
					data: {
						username: this.username,
						password: this.password,
					},
				});
				if (res.statusCode === 200 && res.data.data) {
					// 登录成功，存储 token
					uni.setStorageSync('token', res.data.data.token);
					uni.showToast({
					  title: '登录成功',
					  icon: 'success',
					});
					// 跳转到首页
					uni.switchTab({
					  url: '/pages/home/home',
					});
				  } else {
					// 登录失败提示
					uni.showToast({
					  title: res.data.message || '登录失败',
					  icon: 'none',
					});
				  }
			} catch (error) {
				uni.showToast({
					title: '请求失败，请重试',
					icon: 'none',
				});
			}
		},

		// 注册跳转
		register() {
			uni.navigateTo({
				url: '/pages/register/register', // 跳转到注册页面
			});
		},
	},
};
</script>

<style scoped>
	.loginpages {
	}
	.bak {
		text-align: center;
	}

	.width-vw {
		padding: 0 50upx;
		box-sizing: border-box;
	}

	.height-vh {
		height: 100vh;
	}

	.image {
		width: 200upx;
		height: 200upx;
	}
	.shouji {
		display: flex;
		align-items: center;
		padding: 30upx;
		border-bottom: 1upx solid #EEEEEE;
	}

	.shouji image {
		width: 40upx;
		height: 50upx;
		margin-right: 50upx;
	}

	.denglu {
		height: 90upx;
		text-align: center;
		line-height: 90upx;
		margin-top: 30upx;
		color: #FFFFFF;
		background-color: #ff4e22;
		border-radius: 50upx;
	}

	.box {
		color: #999999;
		padding: 20upx;
		font-size: 26upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.margin020{
		padding-top: 200rpx;
	}
</style>
